#ifndef __TROPHY_SPLITTER_WND_H__
#define __TROPHY_SPLITTER_WND_H__

#include "resource.h"
#include "SimpleWnd/SimpleWnd.h"

enum BarDirection
{
    EastWest, NorthSouth
};

#define SPLITTER_WND_CLASS "TROPHY_Splitter_Window"

class IPaneWindow
{
public:
    virtual HWND CreatePaneWindow(HWND hParent, RECT& rc, DWORD dwStyle, DWORD dwExStyle) = 0;
};

class CSplitterWindow : public CWnd
{
public:
    DECLARE_WND_CLASS_EX(SPLITTER_WND_CLASS, 0, COLOR_3DFACE)

    CSplitterWindow();
    virtual ~CSplitterWindow();
    HWND CreateSplitterWnd (HWND hParent, RECT& rc);
    void SetBarWidth (UINT w);
    void SetParameters(BarDirection direction, 
                    IPaneWindow* pPane1, 
                    IPaneWindow* pPane2, 
                    UINT uPane1Span);
    void SetBarPos(UINT pos);

BEGIN_MSG_MAP(CSplitterWindow)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
    MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
    MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
    MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
    MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
    MESSAGE_HANDLER(WM_SIZE, OnSize)
END_MSG_MAP()

protected:
// Handler prototypes:
    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

    // helpers
    void SetPaneRects(RECT rcPane[2]);
    void DrawSizingBar(UINT uPos);
    void MovePanes();

protected:
    BarDirection        m_direction;
    UINT                m_uPane1Span;
    UINT                m_uBarWidth;
    IPaneWindow*        m_pPanes[2];
    HWND                m_hPanes[2];
    HWND                m_hParent;
    HCURSOR             m_hCursor;
    bool                m_bSizing;
    HPEN                m_pen;
    UINT                m_uSizingPos;
};

#endif // __TROPHY_SPLITTER_WND_H__
